/**
 * Debug-JS Tracing support plugin.
 *
 * @author Matias Mirabelli <admin@moyrax.com>
 */
Debugger.Tracert = Debugger.Plugins.register(Debugger.PluginType.TRACING, null,
                                             function() {
  /**
   * Represents a stack frame. The stack will hold this type
   * of objects.
   *
   * @param theMethod {Function} Method related to this stack frame.
   * @param theName {String}  Name of the method.
   */
  var StackFrame = function(theMethod, theName) {
    var publicInterface = {
      /**
       * Method name.
       */
      methodName : theName,
      /**
       * Previous stack frame.
       */
      previous : null,

      toString : function() {
        return this.methodName;
      }
    };
    return publicInterface;
  };

  var publicInterface = {
    /**
     * Pushs a method into the stack.
     *
     * @param theData {Object} Debugging data for this event.
     */
    push : function(theData) {
      var _frame = new StackFrame(theData.method, theData.methodName);
      var _stack = theData.context.stack;

      _frame.previous = _stack.slice(_stack.length - 1)[0];

      _stack.push(_frame);
    },

    /**
     * Removes the last method from the stack.
     *
     * @param theData {Object} Debugging data for this event.
     */
    pop : function(theData) {
      theData.context.stack.pop();
    }
  };

  return publicInterface;
}());
